<template>
  <div class="list">
    <van-list
      v-model="loading"
      :finished="finished"
      finished-text="没有更多了"
      @load="onLoad"
      class="list-container"
    >
      <!-- <van-cell v-for="item in list" :key="item.id" :title="item.title" /> -->
      <!-- <van-card
        v-for="item in list"
        :key="item.id"
        :num="item.saleNum"
        :price="item.price"
        desc="描述信息"
        :title="item.title"
        :thumb="item.image"
      /> -->
      <div
       v-for="item in list"
       :key="item.id"
       class="list-item"
       is="router-link"
       :to="{name: 'detail', params: {id: item.id}}"
       tag="li"
       >
        <img :src="item.image" alt="">
        <span class="title">{{item.title}}</span>
        <div class="sale-info">
          <span class="price">￥{{item.price}}元</span>
          <span class="buyed">{{item.saleNum}}人已购买</span>
        </div>
      </div>
    </van-list>
  </div>
</template>

<script>
import { getList } from '@/api/list'
export default {
  name: 'List',
  data () {
    return {
      list: [],
      loading: false,
      finished: false,
      page: 1
    }
  },
  methods: {
    onLoad () {
      // 异步更新数据
      // setTimeout 仅做示例，真实场景中一般为 ajax 请求
      getList(this.$route.query.url, this.page).then(res => {
        console.log(res)
        this.list = this.list.concat(res)
        this.page += 1
        this.loading = false
        if (res.length === 0) {
          this.finished = true
        }
      })
    }
  }
  // created () {
  //   // console.log(this.$route.query)
  //   getList(this.$route.query.url).then(res => {
  //     console.log(res)
  //     this.list = res
  //   })
  // }
}
</script>

<style lang="scss" scoped>
  .list{
    &-container {
      display: flex;
      flex-wrap: wrap;
      justify-content: space-between;
    }
    &-item {
      width: 48%;
      margin: 6px 0;
      .title{
        font-weight: 500;
        font-size: 14px;
        line-height: 18px;
      }
      .sale-info{
        margin-top: 10px;
        display: flex;
        justify-content: space-between;
        .price{
          height: 20px;
          line-height: 20px;
          font-size: 16px;
          display: inline-block;
          background: orangered;
          color:white;
          font-weight: 500;
          padding-right: 5px;
        }
        .buyed{
          font-size: 14px;
          color: #868686;
        }
      }

      img {
        max-width: 100%;
      }
    }
  }
</style>
